package db

import (
	"context"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"time"
)

const (
	RmsDns        = "root:Root123456!@tcp(120.76.228.56:3306)/rms?charset=utf8mb4&parseTime=True&loc=Local"
	PmsItemTable  = "pms_item"
	PmsOrderTable = "pms_order"
	PmsCategory   = "pms_category"
	PmsPackage    = "pms_package"
	PmsTable      = "pms_table"
)

var RmsDb *gorm.DB
var err error

func init() {
	RmsDb, err = gorm.Open(mysql.Open(RmsDns), &gorm.Config{})
	if err != nil {
		panic(err)
	}
	sqlDb, err := RmsDb.DB()
	if err != nil {
		panic(err)
	}
	sqlDb.SetConnMaxLifetime(300 * time.Second)
	sqlDb.SetMaxIdleConns(100)
	sqlDb.SetMaxOpenConns(200)
}

func NewRmsDBRequest(ctx context.Context) *gorm.DB {
	return RmsDb.Session(&gorm.Session{Context: ctx})
}
